package com.qianfeng.zw.meilishuo.ui;

import android.support.v4.app.Fragment;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.jayqqaa12.abase.core.Abase;
import com.jayqqaa12.abase.core.activity.AActivity;
import com.qianfeng.zw.meilishuo.BaseApp;
import com.qianfeng.zw.meilishuo.R;
import com.qianfeng.zw.meilishuo.adapter.NavigationTabAdapter;
import com.qianfeng.zw.meilishuo.fragment.ClassifyFragment_;
import com.qianfeng.zw.meilishuo.fragment.CollocationFragment_;
import com.qianfeng.zw.meilishuo.fragment.FindFragment_;
import com.qianfeng.zw.meilishuo.fragment.HomeFragment_;
import com.qianfeng.zw.meilishuo.fragment.QuanFragment_;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;

/**
 *
 */
@EActivity(R.layout.activity_main)
public class MainActivity extends AActivity implements NavigationTabAdapter.OnRgsExtraCheckedChangedListener {
    @ViewById(R.id.home_rgs)
    RadioGroup rgs;
    private long firstTime = 0;
    private ArrayList<Fragment> fragments = new ArrayList<>();

    /**
     * 初始化控件
     */
    @Override
    public void init() {
        fragments.add(new HomeFragment_());
        fragments.add(new ClassifyFragment_());
        fragments.add(new QuanFragment_());
        fragments.add(new CollocationFragment_());
        fragments.add(new FindFragment_());
        NavigationTabAdapter adapter = new NavigationTabAdapter(getSupportFragmentManager(), fragments, R.id.home_fragment_container, rgs);
        adapter.setOnRgsExtraCheckedChangedListener(this);
    }

    @Override
    public void onBackPressed() {
        long secondTime = System.currentTimeMillis();
        if (secondTime - firstTime > 2000) { //如果两次按键时间间隔大于2秒，则不退出
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            firstTime = secondTime;//更新firstTime
            return;
        } else {
            BaseApp.getInstance().unRegister();
            Abase.getAppManager().AppExit();
        }
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {


    }
}
